package com.example.mobile2021606144ywr0407homework;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;
import androidx.constraintlayout.widget.ConstraintLayout;

public class MainActivity6 extends AppCompatActivity {

    private ConstraintLayout txt5;
    private TextView tvMainTitle5;
    private TextView tvMain51;
    private TextView tvMain52;
    private TextView tvMain53;
    private TextView tvMain54;
    private EditText editMain51;
    private Button  btnMain5end ;
    private TextView txt4;
    int x,y;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main6);
        initView();
        btnMain5end.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String string = editMain51.getText().toString();
                int x =Integer.valueOf(string).intValue();
                if (x < 1) {
                    y =x;
                    txt4.setText(y);
                } else if (1 <= x && x < 10) {
                    y = 2 * x - 1;
                    String str1 = String.format("%.2f", y);
                    txt4.setText(str1);
                } else if (x >= 10) {
                   y = 3 * x - 11;
                    String str2 = String.format("%.2f", y);
                    txt4.setText(str2);
                }
            }
        });
    }

    private void initView() {
        txt5 = (ConstraintLayout) findViewById(R.id.txt);
        tvMainTitle5 = (TextView) findViewById(R.id.tv_main_title5);
        tvMain51 = (TextView) findViewById(R.id.tv_main5_1);
        tvMain52 = (TextView) findViewById(R.id.tv_main5_2);
        tvMain53 = (TextView) findViewById(R.id.tv_main5_3);
        tvMain54 = (TextView) findViewById(R.id.tv_main5_4);
        editMain51 = (EditText) findViewById(R.id.edit_main5_1);
        btnMain5end = (Button) findViewById(R.id.btn_main5_end);
        txt4 = (TextView) findViewById(R.id.txt4);
    }
}